import javax.print.attribute.standard.PagesPerMinute;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadDemoPractice30 {
    public static void main(String[] args) {
        //创建一个可以延迟执行任务的线程池
        ExecutorService pool4 = Executors.newScheduledThreadPool(10);
        for (int i = 0; i < 5; i++) {
            int num = i;
            pool4.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println("hello " + num);
                }
            });
        }
    }
    public static void main3(String[] args) {
        //创建线程池中只包含一个线程的线程池
        ExecutorService pool3 = Executors.newSingleThreadExecutor();
        for (int i = 0; i < 100; i++) {
            int num = i;
            pool3.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println("hello " + num);
                }
            });
        }
    }
    public static void main2(String[] args) {
        //创建线程数动态增长的线程池
        ExecutorService pool2 = Executors.newCachedThreadPool();
        for (int i = 0; i < 120; i++) {
            int num = i;
            pool2.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println("hello1" + num);
                }
            });
        }
    }
    public static void main1(String[] args) throws InterruptedException {
        //创建固定线程数的线程池
        ExecutorService pool1 = Executors.newFixedThreadPool(30);
        for (int i = 0; i < 120; i++) {
            int num = i;
            pool1.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println("hello1" + num);
                }
            });
        }
    }
}
